package com.szxy.miaosha.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.boot.test.autoconfigure.data.jdbc.DataJdbcTest;

/**
 * @Auther:wzer
 * @Date:2020/9/5
 * @Description:com.szxy.miaosha.utils
 * @Version:1.0
 **/
@Getter
public class Result<T> {
    private int code;
    private String msg;
    private T data;

    private Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    private Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
        this.data = null;
    }

    private Result(CodeMsg cm) {
        if (cm == null) {
            return;
        }
        this.code = cm.getCode();
        this.msg = cm.getMsg();
        this.data = null;
    }

    public static Result<String> ok() {
        return new Result<String>(200, "ok");
    }

    public static <T> Result success(T data) {
        return new Result(200, "ok", data);
    }

    public static <T> Result success(String msg, T data) {
        return new Result(200, msg, data);
    }

    public static Result error(CodeMsg cm) {
        return new Result(cm);
    }


}
